﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ICTBilling;

/// <summary>
/// Summary description for tbBill
/// </summary>
public partial class tbBill : IValidate
{
    public List<ExceptionHandler> Validate(ChangeAction changeAction)
    {
        List<ExceptionHandler> ExecutionCollection = new List<ExceptionHandler>();
        try
        {
            if (changeAction == ChangeAction.Insert ||
                changeAction == ChangeAction.Update)
            {
                if (changeAction == ChangeAction.Update && this.PkBillID == null)
                    ExecutionCollection.Add(new ExceptionHandler("PkBillID", "شناسه قبض", ICTBilling.ExceptionType.NullArgumant));

                if (this.FkCenterID == null)
                    ExecutionCollection.Add(new ExceptionHandler("FkCenterID", "نام مرکز", ICTBilling.ExceptionType.NullArgumant));

                if (this.StartDate == null)
                    ExecutionCollection.Add(new ExceptionHandler("StartDate", "از تاریخ", ICTBilling.ExceptionType.NullArgumant));
                else
                {
                    try
                    {
                        DateTime.Parse(this.StartDate.ToString());
                    }
                    catch (FormatException)
                    {
                        ExecutionCollection.Add(new ExceptionHandler("StartDate", "از تاریخ", ICTBilling.ExceptionType.DateFormat));
                    }
                }

                if (this.EndDate == null)
                    ExecutionCollection.Add(new ExceptionHandler("EndDate", "تاریخ", ICTBilling.ExceptionType.NullArgumant));
                else
                {
                    try
                    {
                        DateTime.Parse(this.EndDate.ToString());
                    }
                    catch (FormatException)
                    {
                        ExecutionCollection.Add(new ExceptionHandler("EndDate", "تا تاریخ", ICTBilling.ExceptionType.DateFormat));
                    }
                }

                if (this.Type == null)
                    ExecutionCollection.Add(new ExceptionHandler("Type", "نوع انرژی", ICTBilling.ExceptionType.NullArgumant));
                else if (this.Type > 255 || this.Type < 1)
                    ExecutionCollection.Add(new ExceptionHandler("Type", "نوع انرژی", ICTBilling.ExceptionType.ShortFormat));
                else
                {
                    try
                    {
                        byte.Parse(this.Type.ToString());
                    }
                    catch (FormatException)
                    {
                        ExecutionCollection.Add(new ExceptionHandler("Type", "نوع انرژی", ICTBilling.ExceptionType.ShortFormat));
                    }
                }

                if (this.UsedValue == null)
                    ExecutionCollection.Add(new ExceptionHandler("UsedValue", "مقدار مصرف", ICTBilling.ExceptionType.NullArgumant));
                else
                {
                    try
                    {
                        int.Parse(this.UsedValue.ToString());
                    }
                    catch (FormatException)
                    {
                        ExecutionCollection.Add(new ExceptionHandler("UsedValue", "مقدار مصرف", ICTBilling.ExceptionType.IntFormat));
                    }
                }

                if (this.UsedPeriod == null)
                    ExecutionCollection.Add(new ExceptionHandler("UsedPeriod", "تعداد روز دوره", ICTBilling.ExceptionType.NullArgumant));
                else
                {
                    try
                    {
                        int.Parse(this.UsedPeriod.ToString());
                    }
                    catch (FormatException)
                    {
                        ExecutionCollection.Add(new ExceptionHandler("UsedPeriod", "تعداد روز دوره", ICTBilling.ExceptionType.IntFormat));
                    }
                }

                if (this.BillKnow == null)
                    ExecutionCollection.Add(new ExceptionHandler("BillKnow", "شناسه قبض", ICTBilling.ExceptionType.NullArgumant));

                if (this.Price == null)
                    ExecutionCollection.Add(new ExceptionHandler("Price", "مبلغ قبض", ICTBilling.ExceptionType.NullArgumant));
                else
                {
                    try
                    {
                        long.Parse(this.Price.ToString());
                    }
                    catch (FormatException)
                    {
                        ExecutionCollection.Add(new ExceptionHandler("Price", "مبلغ قبض", ICTBilling.ExceptionType.LongFormat));
                    }
                }
            }
        }
        catch (Exception _Exception)
        {
            ExecutionCollection.Add(new ExceptionHandler(_Exception));
        }
        return ExecutionCollection;
    }
}